package com.fluxtah.jordl.examples.twitter;

import com.fluxtah.jordl.lib.Transformer;
import com.fluxtah.jordl.lib.TransformException;
import org.json.JSONObject;
import org.json.JSONException;

public class TweetInputTransformer extends Transformer<JSONObject, Tweet> {
	public void transform(JSONObject source, Tweet target) throws TransformException {
		try {
			if(source.has("created_at") && !source.isNull("created_at")) {
				target.setCreatedAt(source.getString("created_at"));
			}
			if(source.has("favorited") && !source.isNull("favorited")) {
				target.setFavorited(source.getBoolean("favorited"));
			}
			if(source.has("id") && !source.isNull("id")) {
				target.setId(source.getLong("id"));
			}
			if(source.has("id_str") && !source.isNull("id_str")) {
				target.setIdStr(source.getString("id_str"));
			}
			if(source.has("in_reply_to_screen_name") && !source.isNull("in_reply_to_screen_name")) {
				target.setInReplyToScreenName(source.getString("in_reply_to_screen_name"));
			}
			if(source.has("in_reply_to_status_id") && !source.isNull("in_reply_to_status_id")) {
				target.setInReplyToStatusId(source.getLong("in_reply_to_status_id"));
			}
			if(source.has("in_reply_to_status_id_str") && !source.isNull("in_reply_to_status_id_str")) {
				target.setInReplyToStatusIdStr(source.getString("in_reply_to_status_id_str"));
			}
			if(source.has("in_reply_to_user_id") && !source.isNull("in_reply_to_user_id")) {
				target.setInReplyToUserId(source.getLong("in_reply_to_user_id"));
			}
			if(source.has("in_reply_to_user_id_str") && !source.isNull("in_reply_to_user_id_str")) {
				target.setInReplyToUserIdStr(source.getString("in_reply_to_user_id_str"));
			}
			if(source.has("possibly_sensitive") && !source.isNull("possibly_sensitive")) {
				target.setPossiblySensitive(source.getBoolean("possibly_sensitive"));
			}
			if(source.has("retweet_count") && !source.isNull("retweet_count")) {
				target.setRetweetCount(source.getInt("retweet_count"));
			}
			if(source.has("retweeted") && !source.isNull("retweeted")) {
				target.setRetweeted(source.getBoolean("retweeted"));
			}
			if(source.has("source") && !source.isNull("source")) {
				target.setSource(source.getString("source"));
			}
			if(source.has("text") && !source.isNull("text")) {
				target.setText(source.getString("text"));
			}
			if(source.has("truncated") && !source.isNull("truncated")) {
				target.setTruncated(source.getBoolean("truncated"));
			}
			if(source.has("user") && !source.isNull("user")) {
				TwitterUser targetMember = new TwitterUser();
				provider.get(TwitterUserInputTransformer.class).transform(source.getJSONObject("user"), targetMember);
				target.setUser(targetMember);
			}
		} catch (JSONException x) {
			throw new TransformException(x);
		}
	}
}
